home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / GraphicsCards / StormMesa / src / scissor.c < prev    next >
C/C++ Source or Header  |  1999-02-04  |  3KB  |  120 lines

  1. /* $Id: scissor.c,v 3.1 1998/02/08 20:17:42 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  3.0
  6.  * Copyright (C) 1995-1998  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: scissor.c,v $
  26.  * Revision 3.1  1998/02/08 20:17:42  brianp
  27.  * removed unneeded headers
  28.  *
  29.  * Revision 3.0  1998/01/31 21:03:42  brianp
  30.  * initial rev
  31.  *
  32.  */
  33.  
  34.  
  35. #ifdef PC_HEADER
  36. #include "all.h"
  37. #else
  38. #include "context.h"
  39. #include "macros.h"
  40. #include "scissor.h"
  41. #include "types.h"
  42. #endif
  43.  
  44.  
  45. void gl_Scissor( GLcontext *ctx,
  46.          GLint x, GLint y, GLsizei width, GLsizei height )
  47. {
  48.    if (width<0 || height<0) {
  49.       gl_error( ctx, GL_INVALID_VALUE, "glScissor" );
  50.       return;
  51.    }
  52.    if (INSIDE_BEGIN_END(ctx)) {
  53.       gl_error( ctx, GL_INVALID_OPERATION, "glBegin" );
  54.       return;
  55.    }
  56.  
  57.    if (x!=ctx->Scissor.X || y!=ctx->Scissor.Y || 
  58.        width!=ctx->Scissor.Width || height!=ctx->Scissor.Height) {
  59.       ctx->Scissor.X = x;
  60.       ctx->Scissor.Y = y;
  61.       ctx->Scissor.Width = width;
  62.       ctx->Scissor.Height = height;
  63.       ctx->NewState |= NEW_ALL;  /* TODO: this is overkill */
  64.    }
  65. }
  66.  
  67.  
  68.  
  69. /*
  70.  * Apply the scissor test to a span of pixels.
  71.  * Return:  0 = all pixels in the span are outside the scissor box.
  72.  *          1 = one or more pixels passed the scissor test.
  73.  */
  74. GLint gl_scissor_span( GLcontext *ctx,
  75.                GLuint n, GLint x, GLint y, GLubyte mask[] )
  76. {
  77.    /* first check if whole span is outside the scissor box */
  78.    if (y<ctx->Buffer->Ymin || y>ctx->Buffer->Ymax
  79.        || x>ctx->Buffer->Xmax || x+(GLint)n-1<ctx->Buffer->Xmin) {
  80.       return 0;
  81.    }
  82.    else {
  83.       GLint i;
  84.       GLint xMin = ctx->Buffer->Xmin;
  85.       GLint xMax = ctx->Buffer->Xmax;
  86.       for (i=0; x+i < xMin; i++) {
  87.      mask[i] = 0;
  88.       }
  89.       for (i=(GLint)n-1; x+i > xMax; i--) {
  90.      mask[i] = 0;
  91.       }
  92.  
  93.       return 1;
  94.    }
  95. }
  96.  
  97.  
  98.  
  99.  
  100. /*
  101.  * Apply the scissor test to an array of pixels.
  102.  */
  103. GLuint gl_scissor_pixels( GLcontext *ctx,
  104.               GLuint n, const GLint x[], const GLint y[],
  105.               GLubyte mask[] )
  106. {
  107.    GLint xmin = ctx->Buffer->Xmin;
  108.    GLint xmax = ctx->Buffer->Xmax;
  109.    GLint ymin = ctx->Buffer->Ymin;
  110.    GLint ymax = ctx->Buffer->Ymax;
  111.    GLuint i;
  112.  
  113.    for (i=0;i<n;i++) {
  114.       mask[i] &= (x[i]>=xmin) & (x[i]<=xmax) & (y[i]>=ymin) & (y[i]<=ymax);
  115.    }
  116.  
  117.    return 1;
  118. }
  119.  
  120.